//
//  LoginViewController.m
//  BSoftWorkLog
//
//  Created by zarra on 2017/8/3.
//  Copyright © 2017年 zarra. All rights reserved.
//

#import "LoginViewController.h"
#import "BSoftLogService.h"
#import "MBProgressHUD+WJ.h"
#import "ClientDao.h"

@interface LoginViewController ()
-(void)showRootVC;
@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    if (kGetValueForKey(kUserName)!=nil) {
        [self.tfUsername setText:kGetValueForKey(kUserName)];
        [self.tfPassword setText:[ClientDao getPassWord]];
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

- (IBAction)clickButton:(id)sender {
    NSString* userName = [self.tfUsername text];
    NSString* password = [self.tfPassword text];
    
    
    __weak LoginViewController* this = self;
    
    
    [[BSoftLogService shareInstance]userLogin:userName password:password completionHandler:^(NSError *error) {
        if (error!=nil) {
            [this.view makeToast:[error localizedDescription]];
    
        }else{
            [this showRootVC];
        }
    }];
}

-(void)showRootVC{
    UINavigationController* nav = self.navigationController;
    
    UIViewController* loginViewController =
    [[UIStoryboard storyboardWithName:@"Main"
                               bundle:NULL] instantiateViewControllerWithIdentifier:@"RootVC"];
    
    [nav setViewControllers:@[loginViewController] animated:YES];
}
@end
